package com.example.teamtribe.database;

import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;

import org.litepal.crud.DataSupport;

public class Team extends DataSupport implements Parcelable, Comparable<Team> {

    private int id;
    private int realId;
    private int schoolId;
    private String name;
    private String portrait;
    private int score;
    private String createTime;
    private String comment;

    public Team() {
    }

    @Override
    public int compareTo(@NonNull Team o) {
        return realId - o.realId > 0 ? 1 : -1;
    }

    public synchronized boolean saveOrUpdate() {
        return saveOrUpdate("realId = ?", realId + "");
    }


    @Override
    public String toString() {
        return "" + id + realId + schoolId + name + portrait + score + createTime + comment;
    }

    @Override
    public int hashCode() {
        return realId;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Team) {
            Team team = (Team) obj;
            return this.realId == team.realId;
        }
        return false;
    }


    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getRealId() {
        return realId;
    }

    public void setRealId(int realId) {
        this.realId = realId;
    }

    public int getSchoolId() {
        return schoolId;
    }

    public void setSchoolId(int schoolId) {
        this.schoolId = schoolId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPortrait() {
        return portrait;
    }

    public void setPortrait(String portrait) {
        this.portrait = portrait;
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.id);
        dest.writeInt(this.realId);
        dest.writeInt(this.schoolId);
        dest.writeString(this.name);
        dest.writeString(this.portrait);
        dest.writeInt(this.score);
        dest.writeString(this.createTime);
        dest.writeString(this.comment);
    }

    protected Team(Parcel in) {
        this.id = in.readInt();
        this.realId = in.readInt();
        this.schoolId = in.readInt();
        this.name = in.readString();
        this.portrait = in.readString();
        this.score = in.readInt();
        this.createTime = in.readString();
        this.comment = in.readString();
    }

    public static final Parcelable.Creator<Team> CREATOR = new Parcelable.Creator<Team>() {
        @Override
        public Team createFromParcel(Parcel source) {
            return new Team(source);
        }

        @Override
        public Team[] newArray(int size) {
            return new Team[size];
        }
    };
}
